<table>
	<tr style="vertical-align: top;">
<?php



require("dbconn.php");

if (isset($_GET["week"]))
{
	$week = $_GET["week"];
	
	if (isset($_GET["hour"]))
	{
		$hour = "%";
		$day = "%";
		if (strlen($_GET["hour"]) == 1)
		{
			$day = substr($_GET["hour"], 0, 1) . "%";
		}
		if (strlen($_GET["hour"]) >= 2)
		{
			$day = substr($_GET["hour"], 0, 2) . "%";
		}
		if (strlen($_GET["hour"]) >= 3)
		{
			$hour = substr($_GET["hour"], 2, 1) . "%";
		}
		$QUERY = "
			SELECT DISTINCT S.id, S.uur, S.dag
			FROM studieuur S, studieuurklas SK
			WHERE SK.studieuur = S.id
			AND S.week = '$week'
			AND S.uur LIKE '$hour'
			AND S.dag LIKE '$day'
		";
	}
	else
	{
		$QUERY = "
			SELECT DISTINCT S.id, S.uur, S.dag
			FROM studieuur S, studieuurklas SK
			WHERE SK.studieuur = S.id
			AND S.week = '$week'
		";
	}
	//echo $QUERY;
	$resultheader = mysql_query($QUERY) or die(mysql_error());
	$columns = mysql_numrows($resultheader);


	for($i = 0; $i < $columns; $i++)
	{
		$header = mysql_result($resultheader, $i, "dag") . mysql_result($resultheader, $i, "uur"); // de manier waarop je info uit de db haalt
		$sid = mysql_result($resultheader, $i, "id");
		
		$QUERY = "
			SELECT plaatsnr, vak, docentid, lokaal
			FROM plaats
			WHERE plaatsnr IN
			(
				SELECT plaatsnr
				FROM studieuurplaats
				WHERE studieuur = $sid
			)
			ORDER BY lokaal ASC, vak ASC, docentid ASC
		";
			
		$resultdata = mysql_query($QUERY) or die (mysql_error());
		$rows = mysql_numrows($resultdata);

		
		
?>		<td>
			<table id="<?php $rnd = mt_rand(10, 99); print($rnd); ?>" cellspacing="0" align="left" valign="top" class="hourtable">
				<tr>
					<th class="uur" colspan="4">
						<?php print($header); ?> 
					</th>
				</tr>
<?php



		for($j=0; $j < $rows; $j++)
		{
			$plaatsnr = mysql_result($resultdata, $j, "plaatsnr");
			$datavak = mysql_result($resultdata, $j, "vak");
			$datadocentid = mysql_result($resultdata, $j, "docentid");
			$datalokaal = mysql_result($resultdata, $j, "lokaal");



?>				<tr>
					<td id="<?php print($i . $j); ?>">
						<?php print($datavak); ?> 
					</td>
					<td>
						<?php print($datadocentid); ?> 
					</td>
					<td>
						<?php print($datalokaal); ?> 
					</td>
					<td>
						<a class="actionbutton" onclick="delplacefromweek('<?php print("$sid"); ?>', '<?php print("$plaatsnr"); ?>')"><img src="pics/delweek.png" /></a>
					</td>
				</tr>
<?php
		}
?>				<tr>
					<td colspan="3" style="border-top: 2px solid black; border-right: 2px solid black; width: 100px !important;">
						voeg uur toe...
					</td>
					<td style="border-top: 2px solid black; width: 20px !important;">
						<a onclick="document.getElementById('adder_<?php print($header); ?>').style.display = document.getElementById('choser_<?php print($header); ?>').style.display = (document.getElementById('choser_<?php print($header); ?>').style.display == '') ? 'none' : ''; document.getElementById('choosebtn_<?php print($header); ?>').src = (document.getElementById('choser_<?php print($header); ?>').style.display == '') ? 'pics/exphider.png' : 'pics/expchoser.png';" class="actionbutton">
							<img src="pics/expchoser.png" id="choosebtn_<?php print($header); ?>" />
						</a>
					</td>
				</tr>
				<tr style="display: none;" id="adder_<?php print($header); ?>" class="adder">
					<td>
						<input type="text" maxlength="2" id="addHourSubject_<?php print("$header"); ?>" style="font-size: 12px; margin: 0; padding: 0; width: 90%;" onkeyup="reloadHoursChoser('<?php print("$header"); ?>', '<?php print("$sid"); ?>');" />
					</td>
					<td>
						<input type="text" maxlength="3" id="addHourTeacher_<?php print("$header"); ?>" style="font-size: 12px; margin: 0; padding: 0; width: 90%;" onkeyup="reloadHoursChoser('<?php print("$header"); ?>', '<?php print("$sid"); ?>');" />
					</td>
					<td>
						<input type="text" maxlength="3" id="addHourRoomNr_<?php print("$header"); ?>" style="font-size: 12px; margin: 0; padding: 0; width: 90%;" onkeyup="reloadHoursChoser('<?php print("$header"); ?>', '<?php print("$sid"); ?>');" />
					</td>
					<td>
						<a class="actionbutton" onclick="clearadderfield('<?php print("$header"); ?>'); reloadHoursChoser('<?php print("$header"); ?>', '<?php print("$sid"); ?>');"><input type="image" src="pics/delweek.png" /></a>
					</td>
				</tr>
				<tr style="display: none;" id="choser_<?php print($header); ?>">
					<td colspan="5" style="border-top: 2px solid black;">
<?php

require("gethoursChoser.php");

?>					</td>
				</tr>
			</table>
		</td>
<?php



	}
}



?>	</tr>
</table>